package org.javaboy.framework.web.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.javaboy.ai.domain.Models;
import org.javaboy.ai.service.IModelsService;
import org.javaboy.common.constant.AiConstants;
import org.javaboy.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CacheWarmUpService implements ApplicationRunner {
    @Autowired
    RedisCache redisCache;
    @Autowired
    IModelsService modelsService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        LambdaQueryWrapper<Models> qw = new LambdaQueryWrapper<>();
        qw.eq(Models::getDelFlag, 1);
        List<Models> list = modelsService.list(qw);
        for (Models models : list) {
            redisCache.setCacheMapValue(AiConstants.AI_MODEL_NAMES, models.getName(), models);
        }
    }
}
